package com.dss.code_generation.config;

import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import javax.servlet.MultipartConfigElement;
import java.io.File;

/**
 * @Description:
 * @author: dongshoushan
 * @date: 2022年11月17日 18:35
 */
@Configuration
public class MultipartConfig {

    @Resource
    private DssProperties dssProperties;

    @Bean
    MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        String locationTemp = dssProperties.getLocationTemp();
        File tmpFile = new File(locationTemp);
        if (!tmpFile.exists()) {
            tmpFile.mkdirs();
        }
        factory.setLocation(locationTemp);
        return factory.createMultipartConfig();
    }

}